package com.surfilter.shell;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * ShellTask
 * Dis:
 * Created by grom on 2017/7/31.
 */
public class ShellTask {
    public static void main(String[] args) {
        try {
            String[] cmd = new String[] { "/bin/sh", "-c", "cd /usr/local","ls | wc -l" };
            Process ps = Runtime.getRuntime().exec(cmd);
            BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
            StringBuffer sb = new StringBuffer();
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line).append("\n");
            }
            String result = sb.toString();
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
